<?php
/**
 *
 * @author ninteySeven.
 * @date 2023-03-26 11:41
 */

namespace App\Services;


use App\Enum\OrderEnum;
use App\Models\ThirdOrderAllModel;

class ThirdService extends BaseService
{
    /**
     * 获取三方订单信息
     *
     * @param $thirdOrderNo
     * @return array
     * @throws \Exception
     */
    public static function getOrderInfo($thirdOrderNo): array
    {
        try {
            $selectFields = [
                'order_status', 'refund_fee', 'third_order_no',
                'driver_name', 'driver_phone',
                'car_type', 'car_number', 'car_color'
            ];
            $result = ThirdOrderAllModel::query()->where(['third_order_no'=>$thirdOrderNo])->select($selectFields)->first();
            if( empty($result)) throw new \Exception(sprintf("找不到订单信息（%s）", $thirdOrderNo));
            return self::_formatOrderInfo($result->toArray());
        }catch (\Exception $exception){
            throw new \Exception($exception->getMessage());
        }
    }
    private static function _formatOrderInfo($data)
    {
        if($data['order_status'] == OrderEnum::STATUS_CANCEL) $data['order_status'] = '取消';
        else $data['order_status'] = '正常';
        return $data;
    }

}
